﻿var g_resFolder = '/ISV/sharp-team.com/SkypeAddon/_imgs/';

// function to Dial number
function Dial(n) {

    if (!Skype.Client.IsRunning) {
        Skype.Client.Start();
    }


    Skype.Attach();

    Skype.Client.Focus();

    oCall = Skype.PlaceCall(n);
}

// function to Dial number with video
function VideoDial(n) {

    if (!Skype.Client.IsRunning) {
        Skype.Client.Start();
    }


    Skype.Attach();

    Skype.Client.Focus();

    oCall = Skype.PlaceCall(n);

    while (oCall.Status!=5) {
        if (oCall.Status==3 || oCall.Status==7 || oCall.Status==8 || oCall.Status==9 || oCall.Status==10 || oCall.Status==11)
            return;
        window.setTimeout("", 500);
    }

    oCall.StartVideoSend();
    oCall.StartVideoReceive();
}

// function to start a chat whith user N
function Chat(n) {

    if (!Skype.Client.IsRunning) {
        Skype.Client.Start();
    }


    Skype.Attach();

    Skype.Client.Focus();

    oChat = Skype.CreateChatWith(n);

    oChat.OpenWindow();
}

// TODO function to Send SMS to user N
function SendSMS(n) {

    if (!Skype.Client.IsRunning) {
        Skype.Client.Start();
    }


    Skype.Attach();

    Skype.Client.Focus();

    oSms = Skype.CreateSms(1, n);

    //oChat.OpenWindow();
}

//function that returns image status_ico
        function getStatusIcon(status) {
            var imageStatusIco = '';
            switch (status) {
                case 0:
                    imageStatusIco = g_resFolder + 'status_offline.gif';
                    break;
                case 1:
                    imageStatusIco = g_resFolder + 'status_online.gif';
                    break;
                case 2:
                    imageStatusIco = g_resFolder + 'status_away.gif';
                    break;
                case 3:
                    imageStatusIco = g_resFolder + 'status_notavailable.gif';
                    break;
                case 4:
                    imageStatusIco = g_resFolder + 'status_dontdistrib.gif';
                    break;
                case 5:
                    imageStatusIco = g_resFolder + 'status_invisible.gif';
                    break;
                case 7:
                    imageStatusIco = g_resFolder + 'status_skypeme.gif';
                    break;
                default:
                    imageStatusIco = g_resFolder + 'status_offline.gif';
                    break;
            }
            return imageStatusIco;
        }

        //function that returns Status title
        function getStatusTitle(status) {
            var imageStatusIco = '';
            switch (status) {
                case 0:
                    return 'Offline';
                case 1:
                    return 'Online';
                case 2:
                    return 'Away';
                case 3:
                    return 'Not available';
                case 4:
                    return 'Don&quot;t disturb';
                case 5:
                    return 'Invisible';
                case 7:
                    return 'Skype me';
                default:
                    return 'Offline';
            }

        }

        function GetUserStatus(username, image) {

            user = Skype.User(username);
            image.src = getStatusIcon(user.OnlineStatus);
            image.title = getStatusTitle(user.OnlineStatus);
            return image;
        }

